package com.homevip.controller.platform;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.homevip.core.controller.BaseController;
import com.homevip.user.entity.User;
import com.homevip.user.service.UserService;
import com.homevip.util.UserSessionUtil;
import com.homevip.util.gson.JsonUtil;
import com.homevip.web.annotation.DataTypeAnnotation;
import com.homevip.web.annotation.DataTypeEnum;
import com.homevip.web.vo.ResultVo;

/**
 * 管理平台个人资料页面
 * @author panpan
 */

@Controller
@RequestMapping("/platform/profile/*")
public class PlatformProfileController extends BaseController {

	@Autowired UserService userService;

	/**
	 * 修改密码
	 */
	@RequestMapping("/changepass")  
	public void changePass(HttpServletRequest request) {
	}

	/**
	 * 用户密码修改处理
	 */
	@RequestMapping("/ajax_changepass") 
	@DataTypeAnnotation(DataTypeEnum.json)
	public void ajaxChangePass(String password, HttpServletRequest request, HttpServletResponse response) throws Exception{
		ResultVo resultVo = new ResultVo();
		User user = UserSessionUtil.getUser(request);
		if(null != user){
			try {
				user.setPassword(password);
				userService.saveUserPass(user);
			} catch (Exception e) {
				resultVo = new ResultVo(true,"更新失败");
			}
		}
		writeJson(response, JsonUtil.toJson(resultVo));
	}
}
